package com.situ.web.test.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientTCP {

	public static void main(String[] args) throws UnknownHostException, IOException {
		Socket socket = new Socket("127.0.0.1", 6666);
		//向服务器发送数据
		OutputStream outputStream = socket.getOutputStream();
		outputStream.write("你好服务器，我是客户端".getBytes());
		// 接收服务器数据
		InputStream inputStream = socket.getInputStream();
		byte[] b = new byte[100];
		int len = inputStream.read(b);
		System.out.println(new String(b, 0, len));

		inputStream.close();
		outputStream.close();
		socket.close();
	}
}
